<?php
/**
 * pagination 模型
 */
class Mpagination extends item implements ArrayAccess,Iterator{
	public $page;
	public $pagesize;
	public $total;
	public $prefix;
	public $pageVar='page';
	public $pageTotal;


	private $container;


	public function __construct($page,$pagesize,$total,$prefix){
			$this -> page = $page;
			$this -> pagesize = $pagesize;
			$this -> total = $total;
			$this -> prefix = $prefix;
			$this -> pageTotal = ceil(($this->total)/$this->pagesize);
	}

	public function offsetExists($page){
		return isset($this->container[$page]);
	}
	public function offsetGet($page){
		$url = "{$this->prefix}/{$this->pageVar}/$page";
		return $url;
	}
	public function offsetSet($page,$url){
		$this -> container[$page] = $url;
	}
	public function offsetUnset($page){
		unset($this->container[$page]);
	}
	public function current(){
		return $this->container[$this->page];
	}
	public function rewind(){
		$this->page = 0;
	}
	public function key(){
		return $this->page;
	}
	public function next(){
		if(++$this->page>$this->pageTotal){
			return null;
		}
	}
	public function valid(){
		return isset($this->container[$this->page]);
	}
}